#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <time.h>
#include "../common.h"
extern "C" {
#include "../yy.h"
}
#include "../sizer.h"
#include "../pcoder.h"
#include "../display.h"
#include "pic16e.h"
#include "pic16e_asm.h"
#include "pic16e_inst.h"

// 1 -> 2
void PIC16E :: parseJumpItem(Item *ip, int idx){
	if (curFunc != NULL){
		if (ip->type == CON_ITEM){
			if (idx == 1){ ASM_CODE(_LI,_R_A4,ip->val.i); }
			else if (idx == 2) { ASM_CODE(_LI,_R_A5,ip->val.i); }
		}else if(ip->type == ID_ITEM){
			if (ip->fname != curFunc->name){
				errPrint("function not matched error");
			}
			Dnode* dp = serachVarable(ip->vname);
			if (idx == 1){ ASM_CODE(_LW,_R_A4, dp->memStr); }
			else if (idx == 2){ ASM_CODE(_LW,_R_A5, dp->memStr); }
		}
	}
}

void PIC16E :: jeqjne(int code, Item *ip0, Item *ip1, Item *ip2)
{
	char *inst= (code == P_JEQ)? _BEQ: _BNE;
	parseJumpItem(ip0, 1);
	parseJumpItem(ip1, 2);
	ASM_CODE(inst,_R_A4, _R_A5,ip2->val.s);
}

void PIC16E :: jeqjneImmd(int code, Item *ip0, Item *ip1, Item *ip2)
{
	char *inst= (code == P_JEQ)? _BEQ: _BNE;

}

void PIC16E :: jeqjneRomId(int code, Item *ip0, Item *ip1, Item *ip2)
{
	
}

void PIC16E :: jeqjneBits(int code, Item *ip0, Item *ip1, Item *ip2)
{
}